﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LanguageDetector
{
    public sealed class DetectionResult : Language, ICharacterEncoding
    {
        public string Encoding { get; set; }

        public bool IsReliable { get; set; }

        double _confidence;
        public double Confidence
        {
            get { return _confidence; }
            set { _confidence = value > 0 ? value : 0; }
        }

        public Exception Error { get; set; }

        public override string ToString()
        {
            var sb = new StringBuilder("DetectionResult{");
            if (!string.IsNullOrEmpty(ISO2))
            {
                sb.AppendFormat("ISO2={0},", ISO2);
                sb.AppendFormat("Name={0},", Name);
            }
            if (Confidence > 0)
            {
                sb.AppendFormat("Confidence={0},", Confidence);
                sb.AppendFormat("IsReliable={0},", IsReliable);
            }
            if (Error != null)
                sb.AppendFormat("Error={0},", Error.Message);
            sb.Append("}");
            return sb.ToString();
        }
    }
}
